<?php
$orgAccount = $this->Session->read('org_account');
$memAccount = $this->Session->read('member_account');

$unread = 0;
foreach($notifications as $not) {
    $unread += $not['read'] == 0 ? 1 : 0;
}
?>

<!--<ul class="nav navbar-nav navbar-left">
    <li>
        <a href="#" class="text-white text-uc" style="color: #fff;font-size: 24px;">MEMBERZ</a>
    </li>
</ul>
-->
<ul class="nav navbar-nav navbar-right">
    <li>
        <a href='<?php echo $this->Html->url('/member/organisations'); ?>'><i class='fa fa-home'></i> Home</a>
    </li>
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
            <?php echo $orgAccount['Organisation']['name']; ?> <b class="caret"></b>
        </a>
        <ul class="dropdown-menu text-sm animated fadeInUp">
            <?php if(isset($orgAccount['OrganisationRole']['admin_access']) ) { ?>
            <li>
                <a href="<?php echo $this->Html->url('/' . $orgAccount['Organisation']['slug'] . '/settings/general'); ?>"><i class="fa fa-edit"></i> Edit Organization</a>
            </li>
            <li class="divider"></li>
            <?php } ?>
            
            <!--<li>
                <a href="#"><i class="fa fa-pencil"></i> Change Subscription</a>
            </li>-->
            
            <li>
                <a href="<?php echo $this->Html->url('/' . $orgAccount['Organisation']['slug'] . '/organisation/public_view'); ?>"><i class="fa fa-eye"></i> Public View</a>
            </li>
            <li class="divider"></li>
            <li>
                <a href="<?php echo $this->Html->url('/' . $orgAccount['Organisation']['slug'] . '/organisation/logout'); ?>"><i class="fa fa-eject"></i> End Session</a>
            </li>
            <!--<li>
                <a href="#"><i class="fa fa-envelope"></i> Feedback / Support</a>
            </li>-->
        </ul>
    </li>
    <li class="hidden-xs" id="notifications_nav">
        <a href="#" id="notifications_trigger" class="dropdown-toggle" data-toggle="dropdown">
            <i class="fa fa-bell-o text-white"></i>
            <span class="badge up bg-danger m-l-n-sm count-n"><?php echo $unread; ?></span>
        </a>
        <section class="dropdown-menu animated fadeInUp input-s-xl">
            <section class="panel bg-white">
                <header class="panel-heading text-sm">
                    <div class='row'>
                        <div class='col-lg-8'>
                            <strong>You have <span class="count-n"><?php echo $unread; ?></span> notifications</strong>
                        </div>

                        <div class='col-lg-4 text-right'>
                            <a href='<?php echo $this->Html->url(array('controller' => 'organisation', 'action' => 'notifications', 'mark_all_read')); ?>' id='mark_all_read' class='text-info'>Mark All Read</a>
                        </div>
                    </div>
                </header>
                <div id="notifications_popup" class="list-group" style="max-height: 420px; overflow: auto;">
                    <?php echo $this->element('organisation/notifications'); ?>
                </div>
                <footer class="panel-footer text-sm text-right">
                    <!--<a href="#" class="pull-right"><i class="fa fa-cog"></i></a>-->
                    <a class='' href="<?php echo $this->Html->url("/" . $orgAccount['Organisation']['slug'] . "/notifications"); ?>"><i class="fa fa-cog"></i> See all the notifications</a>
                </footer>
            </section>
        </section>
    </li>
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
            <span class="thumb-sm avatar pull-left m-t-n-xs m-r-xs">
                <?php
                $imgPath = isset($memAccount['Member']['MemberImage'][0]) ? $memAccount['Member']['MemberImage'][0]['thumb_url'] : $this->Html->url('/img/avatar_default.jpg');
                ?>
                <img src="<?php echo $imgPath; ?>">
            </span>
            <?php echo $memAccount['Member']['first_name'] . " " . $memAccount['Member']['last_name']; ?> <b class="caret"></b>
        </a>
        <ul class="dropdown-menu animated fadeInLeft">
            <!--<li>
                <a href="#">Settings</a>
            </li>
            <li>
                <a href="<?php echo $this->Html->url('/user/profile'); ?>">Profile</a>
            </li>
            <li>
                <a href="#">
                    <span class="badge bg-danger pull-right">3</span>
                    Notifications
                </a>
            </li>
            <li>
                <a href="<?php echo $this->Html->url('/help'); ?>">Help</a>
            </li>-->
            <li>
                <a href="<?php echo $this->Html->url('/member/profile'); ?>">Profile</a>
            </li>
            <li>
                <a href="<?php echo $this->Html->url('/member/change_password'); ?>">Change Password</a>
            </li>
            <li>
                <a href="<?php echo $this->Html->url('/member/logout'); ?>">Logout</a>                
            </li>
        </ul>
    </li>
</ul>

<input type="hidden" id="app_base_url" value="<?php echo $this->Html->url('/', true); ?>" />